package com.shameit.goodqrinfomanager;

import com.google.gson.Gson;
import com.shameit.goodqrinfomanager.bean.litepal.LoginUser;

import org.litepal.LitePal;

import java.text.SimpleDateFormat;

import me.goldze.mvvmhabit.base.BaseApplication;
import me.goldze.mvvmhabit.utils.SPUtils;

public class MyApplication extends BaseApplication {
    public final static String loginUserKey = "loginUser";
    public final static String TOKEN = "token";
    public final static String TOKEN_VALUE = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJ3ZWIiLCJpc3MiOiJ5dW5qaS1wbHVzIiwiZXhwIjoxNjAyMjU3MDA4LCJpYXQiOjE2MDIyMTM4MDgsImp0aSI6IjAyMzRjNDcyZWE4MTRmZTg4ODBjYWZkMDdhMTVmYzFiIiwidXNlcm5hbWUiOiJhZG1pbiJ9.z5OLkq7sSK_8Gdf9EEXusINNaIhrHxkltUQAm5_xeQ0";
    public final static SimpleDateFormat yyHHMMddhhmmss = new SimpleDateFormat("yyyy-MM-DD hh:mm:ss");
    public final static String BaseUrl = "BaseUrl";

    public static LoginUser loginUser;

    public static void login(LoginUser user) {
        SPUtils.getInstance().put(loginUserKey, new Gson().toJson(user));
        loginUser = user;
    }

    public static void saveHttpMsg(String newUrl){
        SPUtils.getInstance().put(BaseUrl, newUrl);
    }

    public static void loginOut() {
        SPUtils.getInstance().remove(loginUserKey);
        loginUser = null;
    }

    public static void saveToken(String token){
        SPUtils.getInstance().put(TOKEN, token);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        LitePal.initialize(this);
    }
}
